package util;

import java.sql.*;

public class DBConnectionUtil {

	public static Connection getConn() {
		Connection conn = null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");

			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false", "root", "123456");
			System.out.println("...注册成功");
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return conn;
	}

	/**
	 * 关闭
	 * @param pstmt
	 * @param conn
	 */
	public static void close(PreparedStatement pstmt, Connection conn) {

		try {
			if (pstmt != null) {
				pstmt.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();

		}
	}

	/**
	 *关闭
	 * @param pstmt
	 * @param rs
	 * @param conn
	 */
	public static void close(PreparedStatement pstmt, ResultSet rs,
			Connection conn) {
		try {
			if (pstmt != null) {
				pstmt.close();
			}
			if (rs != null) {
				rs.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
